﻿Imports Sistema_InformacionNaviera.BC
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL

Public Class CruceFletes
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            CargarServicio("SR") 
        End If
        If My.Request.Params("__EVENTTARGET") = "MiFuncionPaquetes" Then

            If Session("BSSCodigoEntidadCli") = Nothing Then
                txtCodCsne.Text = String.Empty
            Else
                txtCodCsne.Text = Session("BSSCodigoEntidadCli")
                txtCsne.Text = Session("BSSNombreEntidadCli")
            End If
        End If
        If My.Request.Params("__EVENTTARGET") = "MiFuncionViajes" Then
            If Session("BPCodViaje") = Nothing Then
                txtNave.Text = String.Empty
                txtDescripcionNave.Text = String.Empty
                lblKvje.Text = 0
            Else
                txtNave.Text = Session("BPCodViaje")
                txtDescripcionNave.Text = Session("BPDesViaje")
                lblKvje.Text = Session("BPCodViaje")
            End If
        End If
        If My.Request.Params("__EVENTTARGET") = "MiFuncionPuertos" Then
            If Session("BPCodPuerto") = Nothing Then
                txtPtoOrigen.Text = String.Empty
            Else
                txtPtoOrigen.Text = Session("BPCodPuerto")
                txtDesPtoOrigen.Text = Session("BPDesPuerto")

            End If
        End If
    End Sub

    Public Sub CargarServicio(ByVal sTipo As String)
        Dim listGeneralBE As List(Of GeneralBE) = New List(Of GeneralBE)
        Dim objGeneralBC As GeneralBC = New GeneralBC()

        Dim objUnidadSeleccione As GeneralBE = New GeneralBE
        objUnidadSeleccione.Codigo = 0
        objUnidadSeleccione.Descripcion = "[Seleccione]"
        listGeneralBE.Add(objUnidadSeleccione)
        objUnidadSeleccione.Codigo = sTipo

        listGeneralBE.AddRange(objGeneralBC.ListadoGeneral(objUnidadSeleccione))

        cboServicio.DataSource = listGeneralBE
        cboServicio.DataValueField = "Codigo"
        cboServicio.DataTextField = "Descripcion"
        cboServicio.DataBind()

    End Sub

    Public Sub CargarGridConsulta()
        Dim objCruceFletesBE As New CruceFletesBE
        Dim lstCruceFletesBE As New List(Of CruceFletesBE)
        Dim objUtil As New Funciones
        Dim objCruceFletesBC As New CruceFletesBC

        objCruceFletesBE.Kvje = 0 : objCruceFletesBE.Csne = "" : objCruceFletesBE.Serv = ""
        objCruceFletesBE.Pto = "" : objCruceFletesBE.Nume = ""

        If Val(lblKvje.Text) > 0 Then
            objCruceFletesBE.Kvje = lblKvje.Text
        End If

        If txtCodCsne.Text.Trim <> "" Then
            objCruceFletesBE.Csne = txtCodCsne.Text.Trim
        End If

        If cboServicio.SelectedValue.Trim <> "" And cboServicio.SelectedValue.Trim <> "SR" Then
            objCruceFletesBE.Serv = cboServicio.SelectedValue.Trim
        End If

        If txtPtoOrigen.Text.Trim <> "" Then
            objCruceFletesBE.Pto = txtPtoOrigen.Text.Trim
        End If

        If txtNroBl.Text.Trim <> "" Then
            objCruceFletesBE.Nume = txtNroBl.Text.Trim
        End If 

        lstCruceFletesBE = objCruceFletesBC.CruceFlete(objCruceFletesBE)
        dgBlImportacion.DataSource = lstCruceFletesBE
        dgBlImportacion.DataBind()
    End Sub

    Protected Sub btnSalir_Click(sender As Object, e As EventArgs) Handles btnSalir.Click 
        Response.Redirect("~/Default.aspx", True)
    End Sub

    Protected Sub btnCruce_Click(sender As Object, e As EventArgs) Handles btnCruce.Click
        CargarGridConsulta()
    End Sub
End Class